<?php
include_once ($serverpath.'/Classes/itemf.php');
class factura{
	private $facturaid;
	public $arrayitemf=array();
	private $total;
	private $cantitems;
	
	function __construct($id){
		$this->facturaid=$id;
		$this->armararrayitemf($id);
		$this->contaritems();
	}
	
	private function armararrayitemf($id){
		$serverpath=$_SERVER['DOCUMENT_ROOT'];
		include_once ($serverpath.'/Classes/itemf.php');
		//levanto el carrito
		$filename=$serverpath.'/files/Cart/'.$id.'.txt';
		$file = fopen($filename,"r");
		while (!feof($file)){
			$line = fgets($file);
			$info = explode('|',$line);
			//levanto el libro que obtuve
			$filename2=$serverpath.'/files/Book/'.$info[0].'.txt';
			$file2 = fopen($filename2,"r");
			$line2 = fgets($file2);
			$info2 = explode('|',$line2);
			$this->arrayitemf[] = new itemf($info[0],$info2[0],$info[1],$info2[4]);
			fclose($file2);
		}
	}
	
	private function contaritems(){
		$this->cantitems = count($this->arrayitemf);
	}
	public function get_cantitems(){
		return $this->cantitems;
	}
	public function get_facturaid(){
		return $this->facturaid;
	}
	public function get_total(){
		return $this->total;
	}
	public function get_arrayitemf(){
		return $this->arrayitemf;
	}
	public function get_itemf($indice){
		return $this->arrayitef[$indice];
	}
	

}
?>